package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.AnalysisManage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * created by wangjunfu on 2021-02-24 15:58:34
 */
@Repository
public class AnalysisManageDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(AnalysisManageDao.class);

    public AnalysisManage insert(final AnalysisManage analysisManage) {
        insert("AnalysisManage.insert", analysisManage);
        return analysisManage;
    }

    public Boolean updateInfoById(final AnalysisManage analysisManage) {
        return update("AnalysisManage.updateInfoById", analysisManage) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("AnalysisManage.updateInfoByQuery", query) > 0;
    }

    public AnalysisManage selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("AnalysisManage.selectById", query);
    }

    public AnalysisManage selectByMobileForLogin(final String mobile) {
        Query query = Query.noPage();
        query.put("mobile", mobile);
        return queryForObject("AnalysisManage.selectByMobileForLogin", query);
    }

    public List<AnalysisManage> selectByQuery(final Query query) {
        return queryForList("AnalysisManage.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("AnalysisManage.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        AnalysisManage analysisManage = new AnalysisManage();
        analysisManage.setDeleteFlag(1);
        analysisManage.setId(id);
        analysisManage.setEntId(entId);

        return update("AnalysisManage.updateInfoById", analysisManage) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("AnalysisManage.deleteById", query) > 0;
    }

    //模糊搜索管理员
    public List<Map<String, String>> selectSimilarManage(final Query query) {
        List<Map<String, String>> map = queryForList("AnalysisManage.selectSimilarManage", query);
        return map;
    }

    //获取用户权限菜单代码集合
    public Map<String, String> selectManagerRoleMenu(final Query query) {
        Map<String, String> map = queryForMap("AnalysisManage.selectManagerRoleMenu", query, "menu_name_en", "menu_id");
        return map;
    }
}